package com.shengyijie.model.object.Listobject;

import java.util.ArrayList;
import java.util.List;   

import android.database.Cursor;

import com.shengyijie.model.object.baseobject.AdvertPic;
import com.shengyijie.model.object.baseobject.Category;
import com.shengyijie.model.object.baseobject.Item; 
 

public class AdvertPicList {

	private int count;
	private List<AdvertPic> list;
	
	public AdvertPicList(){
		list=new ArrayList<AdvertPic>();
		count=0;
	}
	
	 
	public void clear(){
		list.clear();
		count=0;
	}
	public int addItem(AdvertPic item){
		list.add(item);
		count++;
		return count;
	}
	
	public int addItemToFirst(AdvertPic item){
		try{
			List<AdvertPic> temp=new ArrayList<AdvertPic>();
			for(int i=0;i<list.size();i++){
				temp.add(list.get(i));
			}
			list.clear();
			list.add(item);
			for(int i=0;i<temp.size();i++){
				list.add(temp.get(i));
			} 
			count++;
		}catch(Exception e){}
		
		return count;
	}
	
	public AdvertPic getItem(int index){
		return list.get(index);
	}
	public void deleteItem(int ID){
		for(int i=0;i<count;i++){
			if(list.get(i).getId()==ID){
				list.remove(i);
				count--;
				return;
			}
		}
		
	}
	
	public List<AdvertPic> getAllItems()
	{
		return list;
	}
	
	public int getCount(){
		return count;
	}
	
	
	public AdvertPicList getAdvertPicListFromCursor(Cursor cursor){
		try{
	   if(cursor==null)
			return null;
	   if(cursor.getCount()>0){
		  for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){ 
			  AdvertPic advertPic=new AdvertPic();
			  advertPic.setId(cursor.getInt(0));
			  advertPic.setPro_name(cursor.getString(1));
			  advertPic.setPic_url(cursor.getString(2));
			  advertPic.setPro_id(cursor.getString(3));
			  advertPic.setCreate(cursor.getString(4));
			 
			  addItem(advertPic);
	    } 
		return this;
	 }
	   cursor.close();
	 return null;
	}catch(Exception e){return null;}
	}

	 
}
